package com.bw.day03.search

import androidx.lifecycle.viewModelScope
import com.bw.base.net.entity.GoodsEntity
import com.bw.base.net.entity.Res
import com.bw.base.net.mvvm.BaseViewModel
import com.bw.day03.utlis.SingleLiveData
import kotlinx.coroutines.launch

class SearchViewModel:BaseViewModel() {
    val searchSuccess=SingleLiveData<Res<GoodsEntity>>()
    val searchFail=SingleLiveData<String>()
    fun search(keyword:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                searchSuccess.postValue(apiService.search(keyword,limit,page))
            }catch (e:Exception){
                searchFail.postValue(e.message.toString())
            }
        }
    }
}